package site.yunnong.atvris.portal.spider.v191;

import com.geccocrawler.gecco.GeccoEngine;
import org.springframework.context.annotation.Bean;
import site.yunnong.atvris.portal.spider.SpringGeccoEngine;
import site.yunnong.atvris.portal.spider.SpringPipelineFactory;

/**
 * @author zjh
 * @date 2021/8/30 0:03
 */
//@Configuration
public class BeanConfig {
    
    @Bean
    public SpringPipelineFactory springPipelineFactory() {
        return new SpringPipelineFactory();
    }
    
    @Bean(name = "v191PagePipeline")
    public V191PagePipeline v191PagePipeline() {
        return new V191PagePipeline();
    }

    @Bean(name = "v191VideoPipeline")
    public V191VideoPipeline v191VideoPipeline() {
        return new V191VideoPipeline();
    }
    
    @Bean
    public SpringGeccoEngine initGecco() {
        return new SpringGeccoEngine() {
            @Override
            public void init() {
                String[] urls = new String[16];
                for (int i = 1; i < 17; i++) {
                    String url = "https://v.191.cn/index/cate?page=" + i + "&id=0&od=0&keywords=";
                    urls[i - 1] = url;
                }
//                GeccoEngine.create()
//                        .classpath("site.yunnong.atvris.portal.spider")
//                        .seed(urls)
//                        .thread(1)
//                        .interval(2000)
//                        .start();
                GeccoEngine.create()
                        .pipelineFactory(springPipelineFactory())
                        .classpath("site.yunnong.atvris.portal.spider")
                        .start(urls)
                        .interval(2000)
                        .start();
            }
        };
    }
}
